﻿//-----------------------------------------------------------------------
// <copyright file="AccountTest.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using GateShift.Common.Repository.Interfaces.DataInterfaces;
using GateShift.Services.GameData.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace GateShift.Testing.Services.GameData.Entities
{
    /// <summary>
    /// Unit Tests for AccountTest
    /// </summary>
    [TestClass]
    public class AccountTest
    {
        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext { get; set; }

        #region AccountName Validation

        /// <summary>
        /// Test for AccountName being Null
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(NullReferenceException))]
        public void AccountName_Null()
        {
            new Account { AccountName = null };
        }

        /// <summary>
        /// Test for AccountName being Too Long
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void AccountName_TooLong()
        {
            new Account { AccountName = string.Empty.PadRight(51, 'A') };
        }

        /// <summary>
        /// Test for AccountName being successful
        /// </summary>
        [TestMethod]
        public void AccountName_Success()
        {
            IAccountData data = new Account { AccountName = "TestName" };
            Assert.AreEqual("TestName", data.AccountName, "Mismatched Data");
        }

        /// <summary>
        /// Test for AccountName being defaulted
        /// </summary>
        [TestMethod]
        public void AccountName_Default()
        {
            IAccountData data = new Account();
            Assert.AreEqual(null, data.AccountName, "Mismatched Data");
        }

        #endregion

        #region EmailAddress Validation

        /// <summary>
        /// Test for EmailAddress being Null
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(NullReferenceException))]
        public void EmailAddress_Null()
        {
            new Account { EmailAddress = null };
        }

        /// <summary>
        /// Test for EmailAddress being too long
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void EmailAddress_TooLong()
        {
            new Account { EmailAddress = string.Empty.PadRight(257, 'A') };
        }

        /// <summary>
        /// Test for EmailAddress being successful
        /// </summary>
        [TestMethod]
        public void EmailAddress_Success()
        {
            IAccountData data = new Account { EmailAddress = "TestName" };
            Assert.AreEqual("TestName", data.EmailAddress, "Mismatched Data");
        }

        /// <summary>
        /// Test for EmailAddress being default
        /// </summary>
        [TestMethod]
        public void EmailAddress_Default()
        {
            IAccountData data = new Account();
            Assert.AreEqual(null, data.EmailAddress, "Mismatched Data");
        }

        #endregion

        #region Password Validation

        /// <summary>
        /// Test for Password being Null
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(NullReferenceException))]
        public void Password_Null()
        {
            new Account { Password = null };
        }

        /// <summary>
        /// Test for Password being too long
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void Password_TooLong()
        {
            new Account { Password = new byte[257] };
        }

        /// <summary>
        /// Test for Password being successful
        /// </summary>
        [TestMethod]
        public void Password_Success()
        {
            IAccountData data = new Account { Password = new byte[256] };
            Assert.AreEqual(256, data.Password.Length, "Mismatched Data");
        }

        /// <summary>
        /// Test for Password being default
        /// </summary>
        [TestMethod]
        public void Password_Default()
        {
            IAccountData data = new Account();
            Assert.AreEqual(null, data.Password, "Mismatched Data");
        }

        #endregion

        #region PasswordSalt Validation

        /// <summary>
        /// Test for PasswordSalt being Null
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(NullReferenceException))]
        public void PasswordSalt_Null()
        {
            new Account { PasswordSalt = null };
        }

        /// <summary>
        /// Test for PasswordSalt being too long
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void PasswordSalt_TooLong()
        {
            new Account { PasswordSalt = new byte[257] };
        }

        /// <summary>
        /// Test for PasswordSalt being successful
        /// </summary>
        [TestMethod]
        public void PasswordSalt_Success()
        {
            IAccountData data = new Account { PasswordSalt = new byte[256] };
            Assert.AreEqual(256, data.PasswordSalt.Length, "Mismatched Data");
        }

        /// <summary>
        /// Test for PasswordSalt being default
        /// </summary>
        [TestMethod]
        public void PasswordSalt_Default()
        {
            IAccountData data = new Account();
            Assert.AreEqual(null, data.PasswordSalt, "Mismatched Data");
        }

        #endregion

        #region RecoveryQuestion Validation

        /// <summary>
        /// Test for RecoveryQuestion being too long
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void RecoveryQuestion_TooLong()
        {
            new Account { RecoveryQuestion = string.Empty.PadRight(257, 'A') };
        }

        /// <summary>
        /// Test for RecoveryQuestion being successful
        /// </summary>
        [TestMethod]
        public void RecoveryQuestion_Success()
        {
            IAccountData data = new Account { RecoveryQuestion = "TestName" };
            Assert.AreEqual("TestName", data.RecoveryQuestion, "Mismatched Data");
        }

        /// <summary>
        /// Test for RecoveryQuestion being default
        /// </summary>
        [TestMethod]
        public void RecoveryQuestion_Default()
        {
            IAccountData data = new Account();
            Assert.AreEqual(null, data.RecoveryQuestion, "Mismatched Data");
        }

        #endregion

        #region RecoveryAnswer Validation

        /// <summary>
        /// Test for RecoveryAnswer being too long
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void RecoveryAnswer_TooLong()
        {
            new Account { RecoveryAnswer = string.Empty.PadRight(129, 'A') };
        }

        /// <summary>
        /// Test for RecoveryAnswer being successful
        /// </summary>
        [TestMethod]
        public void RecoveryAnswer_Success()
        {
            IAccountData data = new Account { RecoveryAnswer = "TestName" };
            Assert.AreEqual("TestName", data.RecoveryAnswer, "Mismatched Data");
        }

        /// <summary>
        /// Test for RecoveryAnswer being default
        /// </summary>
        [TestMethod]
        public void RecoveryAnswer_Default()
        {
            IAccountData data = new Account();
            Assert.AreEqual(null, data.RecoveryAnswer, "Mismatched Data");
        }

        #endregion
    }
}